<!--闭店审核-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <!--      <el-form-item label="用户名" prop="userName">
              <el-input
                v-model="queryParams.userName"
                placeholder="请输入用户"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>-->
      <el-form-item label="店铺名" prop="shopName">
        <el-input
          v-model="queryParams.shopName"
          placeholder="请输入店铺名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="offStatus">
        <dict-select :options="dict.type.audit_type" v-model="queryParams.offStatus" placeholder="请选择审核状态"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="baseList">
      <el-table-column label="店铺名称" align="left" prop="shopName" width="120" :show-overflow-tooltip="true"/>
      <el-table-column label="所属用户" align="left" prop="userName" width="120" :show-overflow-tooltip="true"/>
      <el-table-column label="封面" align="center" prop="shopCoverUrl" width="120" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <oss-image-preview model="text" :src="scope.row.shopCoverUrl"/>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="offStatus" width="200">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.offStatus == '0'">待审批</el-tag>
          <el-tag type="danger" v-if="scope.row.offStatus == '1'">审批不通过</el-tag>
          <el-tag type="success" v-if="scope.row.offStatus == '2'">审批通过</el-tag>
<!--          <dict-tag :options="dict.type.audit_type" :value="scope.row.offStatus"/>-->
        </template>
      </el-table-column>
      <el-table-column label="电话" align="center" prop="phone" width="200" :show-overflow-tooltip="true"/>
      <el-table-column label="简介" align="left" prop="intro" width="220" :show-overflow-tooltip="true"/>
      <el-table-column label="邮箱" align="center" prop="email" width="200" :show-overflow-tooltip="true"/>
      <el-table-column label="闭店理由" align="center" prop="offReason " width="200" :show-overflow-tooltip="true"/>
      <el-table-column label="申请时间" align="center" prop="createTime" width="140" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{m}/{d}/{y}') }}</span>
        </template>
      </el-table-column>
      <!--        <el-table-column label="证件正面照" align="center" prop="cardFrontUrl" width="120"
                               :show-overflow-tooltip="true"
              >
                <template slot-scope="scope">
                  <oss-image-preview :model="'text'" :src="scope.row.cardFrontUrl"/>
                </template>
              </el-table-column>
              <el-table-column label="小店类型" align="center" prop="type" width="100" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                  <dict-tag :options="dict.type.store_business_type" :value="scope.row.type"/>
                </template>
              </el-table-column>
              <el-table-column label="企业名" align="left" prop="companyName" width="120" :show-overflow-tooltip="true"/>

            </el-table-column>
            <el-table-column align="center" label="个人信息"></el-table-column>
            <el-table-column label="whatsapp" align="center" prop="whatsapp" width="120" :show-overflow-tooltip="true"/>
            <el-table-column label="telegram" align="center" prop="telegram" width="120" :show-overflow-tooltip="true"/>
            <el-table-column label="凭证图片" align="center" prop="telegram" width="120" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <oss-image-preview :modal="text" :src="scope.row.shopAvatarUrl"/>
              </template>
            </el-table-column>-->
      <el-table-column :label="$t('operate')" align="center" class-name="small-padding fixed-width" width="180">
        <template slot-scope="scope">
                    <span v-if="scope.row.offStatus == '0'">
                        <el-button size="mini" type="success" class="mini-btn" plain @click="handleClose(scope.row.id)">通过
                        </el-button>
                        <el-button size="mini" class="mini-btn mini-btn-left" type="danger" plain
                                   @click="closeUnPass(scope.row.id)"
                        >拒绝
                        </el-button>
                    </span>
          <span v-else>已审核</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"
    />


  </div>
</template>

<script>
import { getList } from '@/api/store/list'
import { closePass, closeUnPass } from '@/api/store/closeAudit'
import DictSelect from '@/components/DictSelect/index.vue'
import DateRangePicker from '@/components/DateRangePicker/index.vue'
import OssImagePreview from '@/components/ImagePreview/oss-image-preview.vue'
import { delAdvertisement } from '@/api/content/advertisionList'

export default {
  name: 'entryAudit',
  components: { DateRangePicker, DictSelect, OssImagePreview },
  dicts: ['audit_type', 'store_business_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户小店表格数据
      baseList: [],
      // 弹出层标题
      title: '',
      // 查询参数
      queryParams: {
        pageSize: 10,
        pageNum: 1
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询用户小店列表 */
    getList() {
      this.loading = true
      let searchData = this.$deepClone(this.queryParams)
      if (!!!this.queryParams.offStatus) {//默认查询所有闭店申请
        // searchData.statuses = ['3', '4'];//3 申请闭店 4 已关店
        searchData.offStatus = ['0', '1', '2']//闭店审核状态
      } else {
        searchData.offStatus = [searchData.offStatus]
      }
      getList(searchData).then(response => {
        this.baseList = response.data.records
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    async handleClose(id) {
      this.$confirm('同意当前商铺关闭！', '闭店审核', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(async() => {
        await closePass(id)
        this.$modal.msgSuccess('店铺已关闭！')
        this.getList()
      }).catch(() => {

      })
    },
    async closeUnPass(id) {
      this.$confirm('拒绝当前商铺关闭！', '闭店审核', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(async({ value }) => {
        console.log(value)
        await closeUnPass(id)
        this.$modal.msgSuccess('拒绝成功！')
        this.getList()
      }).catch(() => {

      })
    }
  }
}
</script>
